/**
 * @param {number[]} flowerbed
 * @param {number} n
 * @return {boolean}
 */
 var canPlaceFlowers = function(flowerbed, n) {
    const len = flowerbed.length
    if (n == 0) return true
    let count = 0
    for (let i = 0; i < len; ) {
        if (flowerbed[i] == 0 && (flowerbed[i+1] == 0 || !flowerbed[i + 1])) {
            count++
            i += 2
        } else if (flowerbed[i] == 1 && flowerbed[i+1] == 0) {
            i += 2
        } else if (flowerbed[i] == 0 && flowerbed[i+1] == 1) {
            i += 3
        } else {
            return false
        }
        if (count == n) return true;
    }
    return false
};
var canPlaceFlowers = function(flowerbed, n) {
    const len = flowerbed.length
    if (n == 0) return true
    let count = 0
    for (let i = 0; i < len; i++) {
        if (flowerbed[i] == 0 
					&& (i + 1 == flowerbed.length || flowerbed[i + 1] == 0) 
					&& (i == 0 || flowerbed[i - 1] == 0)) {
				flowerbed[i] = 1;
				count++;
			}
    }
    return count>=n;
};
